from jenkinsapi.jenkins import Jenkins


def get_server_instance():
    jenkins_url = 'http://jenkins.imagedz.com'
    server = Jenkins(jenkins_url, username='moumoumou', password='moumoumou')
    return server

#获取jenkins版本
#server = get_server_instance()
#print(server.version)


#输出结果2.277.2
def get_job_details():
    # Refer Example #1 for definition of function 'get_server_instance'
    server = get_server_instance()
    for job_name, job_instance in server.get_jobs():
        print('Job Name:%s' % (job_instance.name))
        print('Job Description:%s' % (job_instance.get_description()))
        print('Is Job running:%s' % (job_instance.is_running()))
        print('Is Job enabled:%s' % (job_instance.is_enabled()))

# 获取项目细节
print(get_job_details())
# 结果
# Job Name:daneng-wholecategory-train1-consumer
# Job Description:
# Is Job running:False
# Is Job enabled:True
# Job Name:daneng-wholecategory-train1-consumer-dev
# Job Description:
# Is Job running:False
# Is Job enabled:True
